Added interrupt method to notify caller method
[appc.git] / appc-inbound / appc-artifact-handler / provider / src / main / java / org / onap / appc / artifact / handler / ArtifactHandlerProvider.java
index dc6489d..3246ef1 100644 (file)
@@ -2,9 +2,11 @@
  * ============LICENSE_START=======================================================
  * ONAP : APPC
  * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Copyright (C) 2017 Amdocs
+ * ================================================================================
+ * Modifications Copyright (C) 2019 Ericsson
  * =============================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -18,7 +20,6 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  * 
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
  * ============LICENSE_END=========================================================
  */
 
@@ -31,6 +32,7 @@ import java.util.concurrent.Future;
 
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
+import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
@@ -67,14 +69,14 @@ public class ArtifactHandlerProvider implements AutoCloseable, ArtifactHandlerSe
     private final String appName = "ArtifactsHandler";
     private final ExecutorService executor;
     protected DataBroker dataBroker;
-    protected NotificationProviderService notificationService;
+    protected NotificationPublishService notificationService;
     protected RpcProviderRegistry rpcRegistry;
     private ListenerRegistration<DataChangeListener> dclServices;
 
     protected BindingAwareBroker.RpcRegistration<ArtifactHandlerService> rpcRegistration;
 
     public ArtifactHandlerProvider(DataBroker dataBroker2,
-            NotificationProviderService notificationProviderService,
+            NotificationPublishService notificationProviderService,
             RpcProviderRegistry rpcProviderRegistry) {
         this.log.info("Creating provider for " + appName);
         executor = Executors.newFixedThreadPool(10);
@@ -96,9 +98,6 @@ public class ArtifactHandlerProvider implements AutoCloseable, ArtifactHandlerSe
         }
         // Listener for changes to Services tree
 
-        rpcRegistration = rpcRegistry.addRpcImplementation(
-                ArtifactHandlerService.class, this);
-
         log.info("Initialization complete for " + appName);
     }
     private void createContainers() {
@@ -112,7 +111,10 @@ public class ArtifactHandlerProvider implements AutoCloseable, ArtifactHandlerSe
             checkedFuture.get();
             log.info("Create containers succeeded!");
 
-        } catch (InterruptedException | ExecutionException e) {
+        } catch (InterruptedException e) {
+            log.error("Create containers failed",  e);
+            Thread.currentThread().interrupt();
+        } catch (ExecutionException e) {
             log.error("Create containers failed",  e);
         }
     }
@@ -148,19 +150,19 @@ public class ArtifactHandlerProvider implements AutoCloseable, ArtifactHandlerSe
             String finalInd) {
 
         UploadartifactOutputBuilder responseBuilder = new UploadartifactOutputBuilder();
-        ConfigDocumentResponseBuilder configResponseBuilder=new ConfigDocumentResponseBuilder();            
-        configResponseBuilder.setRequestId(svcRequestId);            
-        configResponseBuilder.setStatus(code);            
-        configResponseBuilder.setErrorReason(message);            
+        ConfigDocumentResponseBuilder configResponseBuilder=new ConfigDocumentResponseBuilder();
+        configResponseBuilder.setRequestId(svcRequestId);
+        configResponseBuilder.setStatus(code);
+        configResponseBuilder.setErrorReason(message);
         RpcResult<UploadartifactOutput> rpcResult = RpcResultBuilder.<UploadartifactOutput> status(true)
                 .withResult(responseBuilder.build()).build();
-        return rpcResult;            
+        return rpcResult;
     }
 
     @Override
     public Future<RpcResult<UploadartifactOutput>> uploadartifact(UploadartifactInput input) {
 
-        if (input == null || input.getDocumentParameters() == null || input.getDocumentParameters().getArtifactContents() == null ) {        
+        if (input == null || input.getDocumentParameters() == null || input.getDocumentParameters().getArtifactContents() == null ) {
             RpcResult<UploadartifactOutput> rpcResult =
                     buildResponse1("N/A", "N/A", "INVALID_INPUT", "Invalid input, null or empty document information" , "Y");
             return Futures.immediateFuture(rpcResult);
@@ -169,10 +171,9 @@ public class ArtifactHandlerProvider implements AutoCloseable, ArtifactHandlerSe
         ConfigDocumentResponseBuilder configResponseBuilder = new ConfigDocumentResponseBuilder();
         UploadartifactOutputBuilder responseBuilder = new UploadartifactOutputBuilder();
         log.info("Received input = " + input );
-        ArtifactHandlerProviderUtil designUtil = new ArtifactHandlerProviderUtil(input);
+        ArtifactHandlerProviderUtil designUtil = getArtifactHandlerProviderUtil(input);
         configResponseBuilder.setRequestId(input.getRequestInformation().getRequestId());
         try{
-            
             if(input.getRequestInformation().getSource() !=null){
                 if(input.getRequestInformation().getSource().equalsIgnoreCase(SdcArtifactHandlerConstants.DESIGN_TOOL)){
                         designUtil.processTemplate(designUtil.createDummyRequestData());
@@ -181,27 +182,29 @@ public class ArtifactHandlerProvider implements AutoCloseable, ArtifactHandlerSe
                 else
                 {
                     designUtil.processTemplate(designUtil.createRequestData());
-                    configResponseBuilder.setStatus(ArtifactHandlerProviderUtil.DistributionStatusEnum.DEPLOY_OK.toString());        
+                    configResponseBuilder.setStatus(ArtifactHandlerProviderUtil.DistributionStatusEnum.DEPLOY_OK.toString());
                 }
             }
             else
             {
-                throw new Exception("No Tempalte data found");                
+                throw new Exception("No Template data found");
             }
-            
-            
         }
         catch (Exception e) {
 
-            configResponseBuilder.setErrorReason(e.getMessage());            
+            configResponseBuilder.setErrorReason(e.getMessage());
             configResponseBuilder.setStatus(ArtifactHandlerProviderUtil.DistributionStatusEnum.DEPLOY_ERROR.toString());
             log.error("Caught exception looking for Artifact Handler", e);
             log.info("Caught exception looking for Artifact Handler: ");
         }
-        
+
         responseBuilder.setConfigDocumentResponse(configResponseBuilder.build());
         RpcResult<UploadartifactOutput> rpcResult = RpcResultBuilder.<UploadartifactOutput> status(true).withResult(responseBuilder.build()).build();
         return Futures.immediateFuture(rpcResult);
 
     }
+
+    protected ArtifactHandlerProviderUtil getArtifactHandlerProviderUtil(UploadartifactInput input) {
+        return new ArtifactHandlerProviderUtil(input);
+    }
 }