* ============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.
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;
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;
* The Class VidController.
*/
+@org.springframework.stereotype.Service
public class VidServiceImpl implements VidService {
/**
* The Constant LOG.
*/
private static final EELFLoggerDelegate LOG = EELFLoggerDelegate.getLogger(VidServiceImpl.class);
- /**
- * The Constant dateFormat.
- */
+
protected final AsdcClient asdcClient;
private final FeatureManager featureManager;
- @Autowired
private ToscaParserImpl2 toscaParser;
private final LoadingCache<String, ServiceModel> serviceModelCache;
}
}
- 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)
public ServiceModel getService(String uuid) throws AsdcCatalogException {
if (featureManager.isActive(FLAG_SERVICE_MODEL_CACHE)) {
return getServiceFromCache(uuid);
- }else {
+ } else {
return getServiceFromSdc(uuid);
}
}
final Service asdcServiceMetadata = asdcClient.getService(UUID.fromString(uuid));
return getServiceModel(uuid, serviceCsar, tosca, asdcServiceMetadata);
} catch (Exception e) {
- LOG.error("Failed to download and proccess service from SDC", e);
+ LOG.error("Failed to download and process service from SDC", e);
}
return serviceModel;
}
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;
+ }
+}