use of alma.acsdaemon.ServiceDefinitionBuilder in project ACS by ACS-Community.
the class StartServicesHelper method internalGetServicesDescription.
/**
* Return the the XML string describing the services to start by reading the services from the
* TMCDB.
*
* @param daemon That services daemon
* @return The XML and the list of services describing the services to start
* @throws HibernateException In case of error reading the services from the TMCDB
* @throws DaemonException In case of error from the daemon
* @throws TMCDBException If the list of service read from the TMCDB is empty
*/
private AlarmServicesDefinitionHolder internalGetServicesDescription(ServicesDaemon daemon) throws HibernateException, DaemonException, TMCDBException {
if (daemon == null) {
throw new IllegalArgumentException("The daemon can't be null");
}
// Get the service definition builder for the current instance
ServiceDefinitionBuilder srvDefBuilder = null;
try {
srvDefBuilder = daemon.create_service_definition_builder((short) instance);
} catch (Throwable t) {
throw new DaemonException("Error getting the service definition builder", t);
}
logger.log(AcsLogLevel.DEBUG, "ServiceDefinitionBuilder got from the ACS services daemon");
// Get the services from the TMCDB
List<AcsServiceToStart> services = getServicesList();
if (services.isEmpty()) {
throw new TMCDBException("No services to start from TMCDB");
}
logger.log(AcsLogLevel.DEBUG, "Read " + services.size() + " to start from TMCDB");
// Add the services to the service definition builder
try {
/*
* NOTE: some of the paremeters required to start the services are hardcoded
* because the tables of the database do not allow to have them stored
* in the TMCDB.
* For this release it is good enough but if we want to have them available
* in the TMCDB and the explorer then we have to change the table of
* the database too.
*/
for (AcsServiceToStart svc : services) {
if (svc.serviceName == null) {
logger.log(AcsLogLevel.DEBUG, "Adding " + svc.serviceType + "@" + svc.hostName + " to the ServicesDefinitionBuilder");
} else {
logger.log(AcsLogLevel.DEBUG, "Adding " + svc.serviceType + "@" + svc.hostName + " with name " + svc.serviceName + " to the ServicesDefinitionBuilder");
}
switch(svc.serviceType) {
case MANAGER:
{
srvDefBuilder.add_manager(svc.hostName, "", false);
break;
}
case ALARM:
{
srvDefBuilder.add_alarm_service(svc.hostName);
break;
}
case CDB:
{
srvDefBuilder.add_rdb_cdb(svc.hostName, false, configurationName);
break;
}
case IFR:
{
srvDefBuilder.add_interface_repository(svc.hostName, true, false);
break;
}
case LOGGING:
{
srvDefBuilder.add_logging_service(svc.hostName, "Log");
break;
}
case LOGPROXY:
{
srvDefBuilder.add_acs_log(svc.hostName);
break;
}
case NAMING:
{
srvDefBuilder.add_naming_service(svc.hostName);
break;
}
case NOTIFICATION:
{
srvDefBuilder.add_notification_service(svc.serviceName, svc.hostName);
break;
}
default:
{
throw new Exception("Unknown type of service to start: " + svc.serviceType + ", on " + svc.hostName);
}
}
}
} catch (Throwable t) {
throw new DaemonException("Error adding services to the daemon", t);
}
logger.log(AcsLogLevel.DEBUG, "All the services have been added to the ServiceDefinitionBuilder");
String svcsXML = srvDefBuilder.get_services_definition();
StringHolder errorStr = new StringHolder();
if (!srvDefBuilder.is_valid(errorStr)) {
// Error in the XML
throw new DaemonException("Error in the services definition: " + errorStr.value);
} else {
logger.log(AcsLogLevel.DEBUG, "Services successfully validated by the ServicesDefinitionBuilder");
}
return new AlarmServicesDefinitionHolder(svcsXML, Collections.unmodifiableList(services));
}
use of alma.acsdaemon.ServiceDefinitionBuilder in project ACS by ACS-Community.
the class StartServicesHelper method startACSServices.
/**
* Starts the services whose XML definition is in the parameter.
* <P>
* The real starting of services is delegated to {@link #internalStartServices(ServicesDaemon, ServiceDefinitionBuilder, String)}
*
* The starting of the services is delegated to a acs service daemon.
* @param xmlListOfServices The XML describing the list of services to start.
* It is generally returned by getServicesDescription()
*
* @throws GettingDaemonException in case of error getting the services daemon
* @throws DaemonException In case of error from the daemon
*/
public void startACSServices(String xmlListOfServices) throws GettingDaemonException, DaemonException {
if (xmlListOfServices == null || xmlListOfServices.isEmpty()) {
throw new IllegalArgumentException("The XML list of services can't be null nor empty");
}
// Get the reference to the daemon
ServicesDaemon daemon = getServicesDaemon();
// Get the service definition builder for the current instance
ServiceDefinitionBuilder srvDefBuilder = null;
try {
srvDefBuilder = daemon.create_service_definition_builder((short) instance);
} catch (Throwable t) {
throw new DaemonException("Error getting the service definition builder", t);
}
logger.log(AcsLogLevel.DEBUG, "ServiceDefinitionBuilder got from the ACS services daemon");
try {
srvDefBuilder.add_services_definition(xmlListOfServices);
} catch (Throwable t) {
throw new DaemonException("Error adding the list of services to the daemon", t);
}
StringHolder errorStr = new StringHolder();
if (!srvDefBuilder.is_valid(errorStr)) {
// Error in the XML
throw new DaemonException("Invalid XML list of services: " + errorStr.value);
}
internalStartServices(daemon, xmlListOfServices);
}
use of alma.acsdaemon.ServiceDefinitionBuilder in project ACS by ACS-Community.
the class ServicesDaemonTest method testServicesBuilder.
public void testServicesBuilder() throws Exception {
ServiceDefinitionBuilder sdb = daemon.create_service_definition_builder(instanceNumber);
assertNotNull(sdb);
assertEquals("ACS instance number must match the one provided to the factory", instanceNumber, sdb.acs_instance_number());
// now we add services in an order that is not a legal startup order, to check re-ordering
final String cdbPath = System.getProperty("user.dir");
sdb.add_notification_service(systemNotificationServiceDefault.value, host);
sdb.add_manager(host, "", true);
sdb.add_notification_service(systemNotificationServiceLogging.value, host);
// "" means that default name "Log" should be used
sdb.add_logging_service(host, "");
sdb.add_naming_service(host);
sdb.add_xml_cdb(host, true, cdbPath);
sdb.add_interface_repository(host, true, false);
String xmlSrvDef = sdb.get_services_definition();
sdb.close();
System.out.println(xmlSrvDef);
//System.getProperty("line.separator");
String ls = "\n";
String xmlExpected = "<acs_services_definition instance=\"" + instanceNumber + "\">" + ls + "<notification_service name=\"" + systemNotificationServiceDefault.value + "\" host=\"" + host + "\" />" + ls + "<manager host=\"" + host + "\" recovery=\"true\" />" + ls + "<notification_service name=\"" + systemNotificationServiceLogging.value + "\" host=\"" + host + "\" />" + ls + "<logging_service host=\"" + host + "\" />" + ls + "<naming_service host=\"" + host + "\" />" + ls + "<cdb host=\"" + host + "\" recovery=\"true\" cdb_xml_dir=\"" + cdbPath + "\" />" + ls + "<interface_repository host=\"" + host + "\" load=\"true\" wait_load=\"false\" />" + ls + "</acs_services_definition>" + ls;
assertEquals(xmlExpected, xmlSrvDef);
// Run these services
DaemonSequenceCallbackImpl daemonSequenceCallbackImpl = new DaemonSequenceCallbackImpl(logger);
DaemonSequenceCallback daemonSequenceCallback = activateDaemonSequenceCallback(daemonSequenceCallbackImpl);
daemonSequenceCallbackImpl.prepareWaitForDone();
StopWatch sw = new StopWatch(logger);
daemon.start_services(xmlSrvDef, false, daemonSequenceCallback);
assertTrue("The services did not start in 2 minutes", daemonSequenceCallbackImpl.waitForDone(2, TimeUnit.MINUTES));
sw.logLapTime("call start_services");
// Stop the services
daemonSequenceCallbackImpl.prepareWaitForDone();
sw = new StopWatch(logger);
daemon.stop_services(xmlSrvDef, daemonSequenceCallback);
assertTrue("The services did not stop in 2 minutes", daemonSequenceCallbackImpl.waitForDone(2, TimeUnit.MINUTES));
sw.logLapTime("call stop_services");
}
Aggregations