Search in sources :

Example 1 with Services

use of org.opendaylight.controller.config.facade.xml.mapping.config.Services in project controller by opendaylight.

the class ConfigSubsystemFacade method setServicesOnTransaction.

private static void setServicesOnTransaction(final ConfigTransactionClient ta, final ConfigExecution execution) throws DocumentedException {
    Services services = execution.getServices();
    Map<String, Map<String, Map<String, Services.ServiceInstance>>> namespaceToServiceNameToRefNameToInstance = services.getNamespaceToServiceNameToRefNameToInstance();
    for (Map.Entry<String, Map<String, Map<String, Services.ServiceInstance>>> namespaceToServiceToRefEntry : namespaceToServiceNameToRefNameToInstance.entrySet()) {
        for (Map.Entry<String, Map<String, Services.ServiceInstance>> serviceToRefEntry : namespaceToServiceToRefEntry.getValue().entrySet()) {
            String qnameOfService = getQname(ta, namespaceToServiceToRefEntry.getKey(), serviceToRefEntry.getKey());
            Map<String, Services.ServiceInstance> refNameToInstance = serviceToRefEntry.getValue();
            for (Map.Entry<String, Services.ServiceInstance> refNameToServiceEntry : refNameToInstance.entrySet()) {
                ObjectName on = refNameToServiceEntry.getValue().getObjectName(ta.getTransactionName());
                try {
                    if (Services.ServiceInstance.EMPTY_SERVICE_INSTANCE == refNameToServiceEntry.getValue()) {
                        ta.removeServiceReference(qnameOfService, refNameToServiceEntry.getKey());
                        LOG.debug("Removing service {} with name {}", qnameOfService, refNameToServiceEntry.getKey());
                    } else {
                        ObjectName saved = ta.saveServiceReference(qnameOfService, refNameToServiceEntry.getKey(), on);
                        LOG.debug("Saving service {} with on {} under name {} with service on {}", qnameOfService, on, refNameToServiceEntry.getKey(), saved);
                    }
                } catch (final InstanceNotFoundException e) {
                    throw new DocumentedException(String.format("Unable to edit ref name " + refNameToServiceEntry.getKey() + " for instance " + on, e), ErrorType.APPLICATION, ErrorTag.OPERATION_FAILED, ErrorSeverity.ERROR);
                }
            }
        }
    }
}
Also used : Services(org.opendaylight.controller.config.facade.xml.mapping.config.Services) DocumentedException(org.opendaylight.controller.config.util.xml.DocumentedException) InstanceNotFoundException(javax.management.InstanceNotFoundException) HashMap(java.util.HashMap) Map(java.util.Map) ObjectName(javax.management.ObjectName)

Aggregations

HashMap (java.util.HashMap)1 Map (java.util.Map)1 InstanceNotFoundException (javax.management.InstanceNotFoundException)1 ObjectName (javax.management.ObjectName)1 Services (org.opendaylight.controller.config.facade.xml.mapping.config.Services)1 DocumentedException (org.opendaylight.controller.config.util.xml.DocumentedException)1