Bug 1062 - Disallow implicit serviceref creation.
[controller.git] / opendaylight / netconf / config-netconf-connector / src / main / java / org / opendaylight / controller / netconf / confignetconfconnector / operations / editconfig / ReplaceEditConfigStrategy.java
index 43d852e76a32f3b35a8bee016b6ca4ab4f8c6d04..ab993c5ffdc4bf4c095d189fc6794c729697823d 100644 (file)
@@ -8,68 +8,36 @@
 
 package org.opendaylight.controller.netconf.confignetconfconnector.operations.editconfig;
 
-import com.google.common.collect.HashMultimap;
-import com.google.common.collect.Multimap;
+import java.util.Map;
+import java.util.Map.Entry;
+import javax.management.Attribute;
+import javax.management.ObjectName;
 import org.opendaylight.controller.config.util.ConfigTransactionClient;
+import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
+import org.opendaylight.controller.netconf.confignetconfconnector.exception.NetconfConfigHandlingException;
 import org.opendaylight.controller.netconf.confignetconfconnector.mapping.attributes.fromxml.AttributeConfigElement;
-import org.opendaylight.controller.netconf.confignetconfconnector.mapping.config.Services;
+import org.opendaylight.controller.netconf.confignetconfconnector.mapping.config.ServiceRegistryWrapper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import javax.management.Attribute;
-import javax.management.InstanceAlreadyExistsException;
-import javax.management.InstanceNotFoundException;
-import javax.management.ObjectName;
-import java.util.Map;
-import java.util.Map.Entry;
-
 public class ReplaceEditConfigStrategy extends AbstractEditConfigStrategy {
 
     private static final Logger logger = LoggerFactory.getLogger(ReplaceEditConfigStrategy.class);
 
-    private final Multimap<String, String> providedServices;
-
-    public ReplaceEditConfigStrategy() {
-        this.providedServices = HashMultimap.create();
-    }
-
-    public ReplaceEditConfigStrategy(Multimap<String, String> providedServices) {
-        this.providedServices = providedServices;
-    }
-
     @Override
     void handleMissingInstance(Map<String, AttributeConfigElement> configuration, ConfigTransactionClient ta,
-                               String module, String instance, Services services) {
-        ObjectName on = null;
-        try {
-            on = ta.createModule(module, instance);
-            logger.debug("New instance for {} {} created under name {}", module, instance, on);
-            addRefNames(services, providedServices, module, instance, ta, on);
-            executeStrategy(configuration, ta, on, services);
-        } catch (InstanceAlreadyExistsException e) {
-            logger.warn("Error creating instance {}:{}, replace failed", module, instance, e);
-            throw new IllegalStateException("Unable to create new instance for " + module + " : " + instance, e);
-        } catch (InstanceNotFoundException e) {
-            throw new IllegalStateException("Unable to save default ref name for instance " + on, e);
-        }
+                               String module, String instance, ServiceRegistryWrapper services) throws NetconfConfigHandlingException {
+        throw new NetconfConfigHandlingException(
+                String.format("Unable to handle missing instance, no missing instances should appear at this point, missing: %s : %s ",
+                        module,
+                        instance),
+                NetconfDocumentedException.ErrorType.application,
+                NetconfDocumentedException.ErrorTag.operation_failed,
+                NetconfDocumentedException.ErrorSeverity.error);
     }
 
-    private void addRefNames(Services services, Multimap<String, String> providedServices, String module,
-                             String instance, ConfigTransactionClient ta, ObjectName on) throws InstanceNotFoundException {
-        for (Entry<String, String> namespaceToService : providedServices.entries()) {
-
-            if(services.hasRefName(namespaceToService.getKey(),
-                    namespaceToService.getValue(), on))
-                continue;
-
-            String refName = services.getNewDefaultRefName(namespaceToService.getKey(), namespaceToService.getValue(),
-                    module, instance);
-            ta.saveServiceReference(
-                    ta.getServiceInterfaceName(namespaceToService.getKey(), namespaceToService.getValue()), refName, on);
-        }
-    }
     @Override
-    void executeStrategy(Map<String, AttributeConfigElement> configuration, ConfigTransactionClient ta, ObjectName on, Services services) {
+    void executeStrategy(Map<String, AttributeConfigElement> configuration, ConfigTransactionClient ta, ObjectName on, ServiceRegistryWrapper services) throws NetconfConfigHandlingException {
         for (Entry<String, AttributeConfigElement> configAttributeEntry : configuration.entrySet()) {
             try {
                 AttributeConfigElement ace = configAttributeEntry.getValue();