Blueprint migration for ITM
[genius.git] / itm / itm-impl / src / main / java / org / opendaylight / genius / itm / rpc / ItmManagerRpcService.java
index 630e2d83a837e8846d1b38c8f771adfb1988b6d9..bd7fcc19c934880ffee8e770e5c36abd91e0e0dd 100644 (file)
@@ -86,22 +86,35 @@ import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
+@Singleton
 public class ItmManagerRpcService implements ItmRpcService {
 
     private static final Logger LOG = LoggerFactory.getLogger(ItmManagerRpcService.class);
-    DataBroker dataBroker;
-    private IMdsalApiManager mdsalManager;
-
+    private final DataBroker dataBroker;
+    private final IMdsalApiManager mdsalManager;
+    private final IdManagerService idManagerService;
 
-    public void setMdsalManager(IMdsalApiManager mdsalManager) {
-        this.mdsalManager = mdsalManager;
+    @Inject
+    public ItmManagerRpcService(final DataBroker dataBroker,final IdManagerService idManagerService,
+                                final IMdsalApiManager iMdsalApiManager) {
+        this.dataBroker = dataBroker;
+        this.idManagerService = idManagerService;
+        this.mdsalManager = iMdsalApiManager;
     }
 
-    IdManagerService idManagerService;
+    @PostConstruct
+    public void start() throws Exception {
+        LOG.info("ItmManagerRpcService Started");
+    }
 
-    public ItmManagerRpcService(DataBroker dataBroker, IdManagerService idManagerService) {
-        this.dataBroker = dataBroker;
-        this.idManagerService = idManagerService;
+    @PreDestroy
+    public void close() throws Exception {
+        LOG.info("ItmManagerRpcService Closed");
     }
 
     @Override
@@ -148,8 +161,9 @@ public class ItmManagerRpcService implements ItmRpcService {
             }
 
             @Override public void onFailure(Throwable error) {
-                String msg = String.format("Unable to delete DcGatewayIp {} in datastore "+ input.getDestinationIp() + "and tunnel type " + input.getTunnelType());
-                LOG.error("Unable to delete DcGatewayIp {} in datastore for ip "+ input.getDestinationIp() + "and tunnel type " + input.getTunnelType());
+                String msg =
+                        "Unable to delete DcGatewayIp " + input.getDestinationIp() + " in datastore and tunnel type " + input.getTunnelType();
+                LOG.error(msg);
                 result.set(RpcResultBuilder.<Void>failed()
                         .withError(RpcError.ErrorType.APPLICATION, msg, error).build());
             }
@@ -184,7 +198,7 @@ public class ItmManagerRpcService implements ItmRpcService {
 
                 @Override
                 public void onFailure(Throwable error) {
-                    String msg = String.format("Unable to create ext tunnel");
+                    String msg = "Unable to create ext tunnel";
                     LOG.error("create ext tunnel failed. {}. {}", msg, error);
                     result.set(RpcResultBuilder.<Void>failed().withError(RpcError.ErrorType.APPLICATION, msg, error).build());
                 }
@@ -214,8 +228,9 @@ public class ItmManagerRpcService implements ItmRpcService {
             }
 
             @Override public void onFailure(Throwable error) {
-                String msg = String.format("Unable to create DcGatewayIp {} in datastore for ip "+ input.getDestinationIp() + "and tunnel type " + input.getTunnelType());
-                LOG.error("Unable to create DcGatewayIp {} in datastore for ip "+ input.getDestinationIp() + "and tunnel type " + input.getTunnelType());
+                String msg =
+                        "Unable to create DcGatewayIp {} in datastore for ip "+ input.getDestinationIp() + "and tunnel type " + input.getTunnelType();
+                LOG.error(msg);
                 result.set(RpcResultBuilder.<Void>failed()
                         .withError(RpcError.ErrorType.APPLICATION, msg, error).build());
             }
@@ -344,7 +359,7 @@ public class ItmManagerRpcService implements ItmRpcService {
     }
 
     private String getFlowRef(long termSvcTable, int svcId) {
-        return new StringBuffer().append(termSvcTable).append(svcId).toString();
+        return String.valueOf(termSvcTable) + svcId;
     }
 
     @Override
@@ -459,10 +474,11 @@ public class ItmManagerRpcService implements ItmRpcService {
                 return result;
             }
 
-            if(foundVxlanTzone == false)
+            if (!foundVxlanTzone) {
                 result.set(RpcResultBuilder.<Void>failed()
                         .withError(RpcError.ErrorType.APPLICATION, "No VxLan TransportZones configured")
                         .build());
+            }
 
             return result;
         } catch (Exception e) {
@@ -496,13 +512,11 @@ public class ItmManagerRpcService implements ItmRpcService {
                 for (TransportZone tzone : tZones.getTransportZone()) {
                     if (!(tzone.getTunnelType().equals(TunnelTypeVxlan.class)))
                         continue;
-                    foundVxlanTzone = true;
                     String transportZone = tzone.getZoneName();
                     if (tzone.getSubnets() == null || tzone.getSubnets().isEmpty()) {
-                        result.set(RpcResultBuilder.<Void>failed()
-                                .withError(RpcError.ErrorType.APPLICATION, "No subnets Configured").build());
-                        return result;
+                        continue;
                     }
+                    foundVxlanTzone = true;
                     SubnetsKey subnetsKey = tzone.getSubnets().get(0).getKey();
                     DeviceVtepsKey deviceVtepKey = new DeviceVtepsKey(hwIp, node_id);
                     InstanceIdentifier<DeviceVteps> path = InstanceIdentifier.builder(TransportZones.class)
@@ -537,10 +551,11 @@ public class ItmManagerRpcService implements ItmRpcService {
                 return result;
             }
 
-            if(foundVxlanTzone == false)
+            if (!foundVxlanTzone) {
                 result.set(RpcResultBuilder.<Void>failed()
                         .withError(RpcError.ErrorType.APPLICATION, "No VxLan TransportZones configured")
                         .build());
+            }
 
             return result;
         } catch (Exception e) {