Merge changes Ib4430bf2,Icc0bdb9e,I2736b984
[vid.git] / vid-app-common / src / main / java / org / onap / vid / services / VidServiceImpl.java
index aedd1b9..9d6f74d 100644 (file)
@@ -2,8 +2,8 @@
  * ============LICENSE_START=======================================================
  * VID
  * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2018 Nokia. All rights reserved.
+ * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2018 - 2019 Nokia. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -23,6 +23,7 @@ package org.onap.vid.services;
 import com.google.common.cache.CacheBuilder;
 import com.google.common.cache.CacheLoader;
 import com.google.common.cache.LoadingCache;
+import io.joshworks.restclient.http.HttpResponse;
 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
 import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException;
 import org.onap.vid.asdc.AsdcCatalogException;
@@ -33,7 +34,11 @@ import org.onap.vid.asdc.parser.ToscaParserImpl;
 import org.onap.vid.asdc.parser.ToscaParserImpl2;
 import org.onap.vid.exceptions.GenericUncheckedException;
 import org.onap.vid.model.ServiceModel;
+import org.onap.vid.model.probes.ExternalComponentStatus;
+import org.onap.vid.model.probes.HttpRequestMetadata;
+import org.onap.vid.utils.Logging;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpMethod;
 import org.togglz.core.manager.FeatureManager;
 
 import java.nio.file.Path;
@@ -47,6 +52,7 @@ import static org.onap.vid.properties.Features.FLAG_SERVICE_MODEL_CACHE;
  * The Class VidController.
  */
 
+@org.springframework.stereotype.Service
 public class VidServiceImpl implements VidService {
     /**
      * The Constant LOG.
@@ -56,7 +62,6 @@ public class VidServiceImpl implements VidService {
     protected final AsdcClient asdcClient;
     private final FeatureManager featureManager;
 
-    @Autowired
     private ToscaParserImpl2 toscaParser;
     private final LoadingCache<String, ServiceModel> serviceModelCache;
 
@@ -67,10 +72,11 @@ public class VidServiceImpl implements VidService {
         }
     }
 
-    public VidServiceImpl(AsdcClient asdcClient, FeatureManager featureManager) {
+    @Autowired
+    public VidServiceImpl(AsdcClient asdcClient, ToscaParserImpl2 toscaParser, FeatureManager featureManager) {
         this.asdcClient = asdcClient;
         this.featureManager = featureManager;
-
+        this.toscaParser=toscaParser;
         this.serviceModelCache = CacheBuilder.newBuilder()
                 .maximumSize(1000)
                 .expireAfterAccess(7, TimeUnit.DAYS)
@@ -96,7 +102,7 @@ public class VidServiceImpl implements VidService {
     public ServiceModel getService(String uuid) throws AsdcCatalogException {
         if (featureManager.isActive(FLAG_SERVICE_MODEL_CACHE)) {
             return getServiceFromCache(uuid);
-        }else {
+        } else {
             return getServiceFromSdc(uuid);
         }
     }
@@ -136,10 +142,26 @@ public class VidServiceImpl implements VidService {
             return tosca.makeServiceModel(uuid, serviceCsar, asdcServiceMetadata);
         }
     }
-    
+
     @Override
-    public void invalidateServiceCache(){
+    public void invalidateServiceCache() {
         serviceModelCache.invalidateAll();
     }
 
-}
\ No newline at end of file
+    @Override
+    public ExternalComponentStatus probeComponent() {
+        long startTime = System.currentTimeMillis();
+        ExternalComponentStatus externalComponentStatus;
+        try {
+            HttpResponse<String> stringHttpResponse = asdcClient.checkSDCConnectivity();
+            HttpRequestMetadata httpRequestMetadata = new HttpRequestMetadata(HttpMethod.GET, stringHttpResponse.getStatus(), asdcClient.getBaseUrl() + AsdcClient.URIS.HEALTH_CHECK_ENDPOINT, stringHttpResponse.getBody(), "SDC healthCheck",
+                    System.currentTimeMillis() - startTime);
+            externalComponentStatus = new ExternalComponentStatus(ExternalComponentStatus.Component.SDC, stringHttpResponse.isSuccessful(), httpRequestMetadata);
+        } catch (Exception e) {
+            HttpRequestMetadata httpRequestMetadata = new HttpRequestMetadata(HttpMethod.GET, 0,
+                    AsdcClient.URIS.HEALTH_CHECK_ENDPOINT, "", Logging.exceptionToDescription(e), System.currentTimeMillis() - startTime);
+            externalComponentStatus = new ExternalComponentStatus(ExternalComponentStatus.Component.SDC, false, httpRequestMetadata);
+        }
+        return externalComponentStatus;
+    }
+}